<?php
/**
 * @package scuttle
 * @file /blocks/scuttle_bookmarks_new.php
 **/


if( ! defined( 'XOOPS_ROOT_PATH' ) ) exit ;

require_once XOOPS_MODULE_PATH. '/scuttle/include/TagService.php';

class Scuttle_NewEntriesBlock extends Legacy_BlockProcedure {

	public function __construct(&$block)
	{
		parent :: Legacy_BlockProcedure($block);
	}

	function prepare()
	{
	}

	function execute()
	{
		$block = array();

		$root =& XCube_Root::getSingleton();

		$handler = xoops_getmodulehandler('bookmarks','scuttle');

		$mCriteria =& new CriteriaCompo();
		$mCriteria->setSort('bModified','DESC');
		$mCriteria->setLimit($this->_mBlock->get('options'));
		$this->mObjects =& $handler->getObjects($mCriteria);

		foreach($this->mObjects as $module) {
			$item['image']        = $module->get('image');
			$item['bAddress']     = $module->get('bAddress');
			$item['bTitle']       = $module->get('bTitle');
			$item['bDescription'] = $module->get('bDescription');
			$ItemArray[] =& $item;
			unset($item);
		}

		$renderTarget =& $this->getRenderTarget();
		$renderTarget->setTemplateName($this->_mBlock->get('template'));
		$renderTarget->setAttribute('item_array' , $ItemArray);
		$renderSystem = $root->getRenderSystem($this->getRenderSystemName());
		$renderSystem->renderBlock($renderTarget);
	}

	// Option setting
	function getOptionForm()
	{
		$options = explode('|', $this->_mBlock->get('options'));

		$root =& XCube_Root::getSingleton();
		$renderSystem =& $root->getRenderSystem('Legacy_AdminRenderSystem');
		$renderTarget =& $renderSystem->createRenderTarget();
		$renderTarget->setAttribute('legacy_module', 'scuttle');
		$renderTarget->setTemplateName('block_new_entries_option.html');
		$renderTarget->setAttribute('viewcount', $options[0]);
		$renderSystem->render($renderTarget);
		return $renderTarget->getResult();
	}
}

?>